/**
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.jimm.protocols.icq.integration.events;

import java.util.EventObject;
import java.util.List;

import org.jimm.protocols.icq.contacts.Contact;
import org.jimm.protocols.icq.packet.received.ssi.SsiContactListReply__19_6;

/**
 * <p>
 * Created by
 * 
 * @author Lo�c Broquet
 */
public class ContactListEvent extends EventObject {

//	private static final String LOG_TAG = "Jimm:ContactListEvent";

	private static final long serialVersionUID = -3740165191665792396L;

//	private Group root;
	public List<Contact> contactList;

	/**
	 * Creates a new instance of ContactListEvent
	 */
	public ContactListEvent(SsiContactListReply__19_6 source, List<Contact> contacts) {
		super(source);
		
		contactList = contacts;

/*		SortedMap<Short, Group> grpMap = new java.util.TreeMap<Short, Group>();
		SortedMap<Short, Item> contMap = new java.util.TreeMap<Short, Item>();

		for (Iterator<Item> iter = source.getItemsIterator(); iter.hasNext();) {
			Item item = iter.next();
			switch (item.getType()) {
			case Item.TYPE_IGNORE_LIST:
			case Item.TYPE_CONTACT:
				try {
					Integer.parseInt(item.getName());
					contMap.put(new Short(item.getId()), item);
				} catch (Exception e) {
					Log.e(LOG_TAG, "Incorrect UIN " + item.getName());
				}
				break;
			case Item.TYPE_GROUP:
				grpMap.put(new Short(item.getGroup()), new Group(item));
				break;
			case Item.TYPE_CONTACT_ICON:
				break;
			}
		}

		for (Iterator<Item> iter = contMap.values().iterator(); iter.hasNext();) {
			Item item = iter.next();
			Group grp = (Group) grpMap.get(new Short(item.getGroup()));
			if (grp == null) {
				Log.d(LOG_TAG,
						"Ne mogu naiti gruppu! contact.id = " + item.getId()
								+ " contact.grp = " + item.getGroup());
				continue;
			}
			grp.addItem(new Contact(item));
		}

		root = (Group) grpMap.remove(new Short((short) 0x0000));
		if (root == null)
			root = new Group((short) 0x0000, EMPTY);

		for (Iterator<Group> iter = grpMap.values().iterator(); iter.hasNext();) {
			Group grp = iter.next();
			root.addItem(grp);
		}*/
	}
}
